package com.example.demo.RedisTest.RedisOne;

import com.example.demo.RedisTest.config.RedisConstant;
import com.example.demo.RedisTest.config.RedisUtils;
import com.example.demo.config.dateUtil.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;

/**
 * @author FF998
 */
@Service
@Slf4j
public class RedisOneServiceImpl implements RedisOneService {

    @Autowired
    private RedisUtils redisUtils;

    @Override
    public void redisTestSave() {
        String time = RedisConstant.TIME;

        HashMap<String, String> map = new HashMap<>();
        Date date = new Date();
        map.put("format", DateUtil.format(date, "yyyy-MM-dd HH:mm:ss"));

        System.out.println("写入前:" + map.get("format"));
        try {
            redisUtils.cacheValue(time, map.get("format"));
            System.out.println("写入后:" + redisUtils.getValue(time));
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("写入Redis失败!");
        }
    }
}
